package com.conti.controller.admin;


import com.conti.dto.DownTimeCodeDTO;
import com.conti.dto.LinePageQueryDTO;
import com.conti.dto.LineQueryDTO;
import com.conti.dto.ShiftBookDTO;
import com.conti.entity.CTAndCustomer;
import com.conti.entity.DowntimeReason;
import com.conti.entity.PartNumber;
import com.conti.result.PageResult;
import com.conti.result.Result;
import com.conti.service.LineService;
import com.conti.vo.LineNoPagingVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 产线管理
 */

@RestController
@RequestMapping("/admin/line")
@Api(tags = "产线相关接口")
@Slf4j

public class LineController {

    @Autowired
    private LineService lineService;

    /**
     * 新增班次报告
     * @param shiftBookDTOList
     * @return
     */
    @PostMapping("/addShiftBook")
    @ApiOperation("新增班次报表")
    public Result addNewShiftBook(@RequestBody List<ShiftBookDTO> shiftBookDTOList) {
        log.info("新增班次报告：{}", shiftBookDTOList);
        lineService.addNewShiftBook(shiftBookDTOList);
        return Result.success();
    }

    /**
     * 产线分页查询
     * @param linePageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("产线分页查询")
    public Result<PageResult> page(LinePageQueryDTO linePageQueryDTO) {
        log.info("产线分页查询:{}", linePageQueryDTO);
        PageResult pageResult = lineService.pageQuery(linePageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 产线查询，无需分页版
     * @param lineQueryDTO
     * @return
     */
    @GetMapping("/queryNoPage")
    @ApiOperation("产线查询groupt版")
    public Result<List<LineNoPagingVO>> queryNoPaging(LineQueryDTO lineQueryDTO) {
        log.info("产线查询：:{}", lineQueryDTO);
        List<LineNoPagingVO> list = lineService.queryNoPaging(lineQueryDTO);
        return Result.success(list);
    }

    /**
     * 根据产线查询料号
     * @param line
     * @return
     */
    @GetMapping("/getPartNumber")
    @ApiOperation("根据产线查询料号")
    public Result<List<PartNumber>> getPartNumber(String line) {

        List<PartNumber> list = lineService.getPartNumberByLine(line);
        return Result.success(list);
    }

    /**
     * 根据产线代码查询停机原因
     * @param downTimeCodeDTO
     * @return
     */
    @GetMapping("/getDowntimeReason")
    @ApiOperation("根据部门和产线查询停机原因")
    public Result<List<DowntimeReason>> getDowntimeReason(DownTimeCodeDTO downTimeCodeDTO) {
        log.info("根据部门和产线查询停机原因:{}", downTimeCodeDTO);
        List<DowntimeReason> list = lineService.getDowntimeReason(downTimeCodeDTO);
        log.info("查询结果:{}", list);
        return Result.success(list);
    }

    /**
     * 获取料号的消费者和CT时间
     * @param partNumber
     * @param equipment
     * @return
     */
    @GetMapping("/getCTAndCustomer")
    @ApiOperation("根据料号和产线获取料号的消费者和CT时间")
    public Result<CTAndCustomer> getCTAndCustomer(String partNumber, String equipment) {
        CTAndCustomer ctAndCustomer = lineService.getCTAndCustomer(partNumber, equipment);
        return Result.success(ctAndCustomer);
    }


}
